/**
 * Description
 *
 * Creation Date 15/12/2017
 * @author Candy
 */

// import axios from 'axios';
{/*<script src="https://cdn.bootcss.com/axios/0.16.0/axios.min.js"></script>*/}
// axios.defaults.baseURL = 'http://192.168.1.199:3389';
axios.defaults.baseURL = 'http://192.168.1.199:3389';
axios.defaults.withCredentials = true;
// axios.defaults.headers.common['Authorization'] = AUTH_TOKEN;
// axios.defaults.headers.post['Content-Type']='application/x-www-form-urlencoded';

//home banner
export const getHomeBanner = () => axios({
	method: 'get',
	url: '/v3/banners'
});

export  const categories = type => axios({
	method: 'get',
	url: '/Category',
	params: {type}
});

export const product = (keyword, brandId, categoryId, genderId, sort) => axios({
	method: 'get',
	url: '/product/list',
	params: {keyword, brand_id : brandId, category_id: categoryId, gender_id: genderId, sort}
});

export const productDetail = product_id => axios({
	method: 'get',
	url: '/product/' + product_id,
});

export const getCaptchas = () => axios({
	method: 'post',
	url: '/v1/captchas'
});

export const getUser = () => axios({
	method: 'get',
	url: '/v1/user'
});

export const getUserById = user_id => axios({
	method: 'get',
	url: '/v1/user/' + user_id,
});

export const login = (username, password, cap) => axios({
	method: 'post',
	url: '/v1/login',
	data: {username, password, cap}
});

export const signout = () => axios({
	method: 'get',
	url: '/v1/signout',
});

export const getAddress = (user_id) => axios({
	method: 'get',
	url: '/v1/users/' + user_id +'/addresses',
});

export const addAddress = (user_id, name, gender, mobile, email, address, is_active) => axios({
	method: 'post',
	url: '/v1/users/' + user_id +'/addresses',
	data: {name, gender, mobile, email, address, is_active}
});

export const deleteAddress = (user_id, address_id) => axios({
	method: 'delete',
	url: '/v1/users/' + user_id +'/addresses/' + address_id,
});

export const getAddressById = (user_id, address_id) => axios({
	method: 'get',
	url: '/v1/users/' + user_id +'/addresses/' + address_id,
});

export const updateAddress = (user_id, address_id, name, gender, mobile, email, address, is_active) => axios({
	method: 'put',
	url: '/v1/users/' + user_id +'/addresses/' + address_id + '/new',
	data: {name, gender, mobile, email, address, is_active}
});

export const checkout = (user_id, entities=[]) => axios({
	method: 'post',
	url: '/v1/carts',
	params: {user_id},
	data: {entities}
})

export const getCartInfo = (user_id, cart_id) => axios({
	method: 'get',
	url: '/v1/carts',
	params: {user_id, cart_id},
})

export const deleteCartInfo = (user_id, cart_id) => axios({
	method: 'delete',
	url: '/v1/carts',
	params: {user_id, cart_id},
})

export const getCartList = (user_id, cart_id) => axios({
	method: 'get',
	url: '/v1/carts/list',
	params: {user_id, cart_id},
})

export const addOrder = (total, cart, address) => axios({
	method: 'post',
	url: '/v1/orders',
	data: {total, cart, address}
})

export const getOrder = (order_id,user_id) => axios({
	method: 'get',
	url: '/v1/orders',
	params: {order_id, user_id}
})
export const getOrderList = (user_id) => axios({
	method: 'get',
	url: '/v1/orders/list',
	params: {user_id}
})
